package org.dftproject.genesis.ui.pages.pedigree.icon;

import org.dftproject.genesis.data.genealogy.Sex;
import org.dftproject.genesis.ui.pages.pedigree.tree.OneToManyConnection;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

public class NodeFigure extends Figure {

	public final Color borderColor = new Color(null, 0x88, 0x88, 0x88);
	private final Color maleColor = new Color(null, 0xBB, 0xBB, 0xFF);
	private final Color femaleColor = new Color(null, 0xFF, 0xBB, 0xBB);

	private final Sex sex;
	
	private OneToManyConnection ancestorConnection;
	
	public NodeFigure(Sex sex) {
		this.sex = sex;
		
		setPreferredSize(14, 6);
	}
	
	@Override
	public void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);
		
		graphics.pushState();
	
		graphics.setBackgroundColor(sex == Sex.Male ? maleColor : femaleColor);
		graphics.fillRoundRectangle(getBounds().getCropped(new Insets(1)), 2, 2);

		graphics.setAntialias(SWT.ON);
		graphics.setForegroundColor(borderColor);
		graphics.drawRoundRectangle(getBounds().getResized(-1, -1), 2, 2);

		graphics.popState();
	}
	
	public void setAncestorConnection(OneToManyConnection connection) {
		ancestorConnection = connection;
		ancestorConnection.setSourceAnchor(this);
	}
	
}
